
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
		<link href="__INDEX__/css/Phoebe.css" rel="stylesheet"/>
		<link href="__INDEX__/css/all.css" rel="stylesheet"/>
		<link href="__INDEX__/css/stock.css" rel="stylesheet"/>
		<title>进货</title>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a href="javascript:history.back(-1)" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">进货</h1>
			<a href="/index.php/Home/Product/stock_rule.html">规则</a>
		</header>
		<!--进货-->
		<div class="stock">
			<form action="">
				<div>
					<span>产品名称 :</span>
                   
					<select name="" id="sel">
						<option value="">请选择产品</option>
                    	{foreach name="goods" item="gd"}
                    	<option value="{$gd.id}">{$gd.name}</option>
                    	{/foreach}
					</select>
                   
				</div>
				<div>
					<div>
						<span>进货出价 :</span>
                        <input type="text" id="offer" name="stock_buy_price" onblur="amount(this)"/>
					</div>
				</div>
				<div>
					<div>
						<span>进货数量 :</span>
						<input type="tel"  id="stock_num" name="stock_buy_num" />
					</div>
                  
				</div>
				<div class="submit" >确认操作</div>
			</form>
		</div>
		<!--出价记录-->
		<div class="money-list" id="cha">
			<ul>
				<li>
					<div>用户ID</div>
					<div>出价</div>
				</li>
			</ul>
		</div>
		<!--model-->
		<div class="my-modal">
			<div>
				<h2>进货确认</h2>
				<div>
					<p>产品名称：<span>产品名称</span></p>
					<div>
						<ul>
							<li>进货出价：<span></span></li>
							<li>进货数量：<span></span></li>
						</ul>
					</div>
					<p id="xianyin"></p>
					<div>
						<button class="stock_conf">确认</button>
						<button class="close-stock">取消</button>
					</div>
				</div>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="/public/static/js/jquery.min.js"></script>
		<script src="/public/static/layui/layui.all.js"></script>
		<!--<script type="text/javascript" src="js/stock.js"></script>-->
        <script>
			layui.config({
				base: '/public/static/js/'
			}).use('admin');
			var user_id='{$Think.session.uid}';
			
        	if(user_id==""||user_id==null){
        		layer.msg("请先登录", {
					icon: 1,
					time: 1000 //2秒关闭（如果不配置，默认是3秒）
				}, function() {
					location.href = "{:url('index/login')}";
				});
        	}
            var pro_xinxi=[];
			$("#sel").change(function(){
				if($(this).val()!=""){
					$('#cha ul').html("<li> <div>用户ID</div> <div>出价</div> </li>");
	                $.ajax({
	                    url: "{:url('index/get_bs')}",
	                    data:{
	                        goods_id:$(this).val(),
	                    },
	                    success:function ( data ) {
	                    	var order=data.order;
	                    	if(order){
								$('#cha ul').append(str);	                    		
	                    	}
	                    }
	                })
				}
			});
           // console.log(11);

            $(".submit").click(function(){
                id=$('#sel').val();
				if(!id){
                    layer.msg('请选择商品！');
				}else if(($('#offer').val())*1==''){
                    layer.msg('请输入价格！');
				}else if(($('#stock_num').val())==''){
                    layer.msg('请输入进货数量！');
				}else if(($('#offer').val())*1 >  pro_xinxi[0]*1*(1+0.1)){
                    if(($('#stock_num').val())*1 > pro_xinxi[1]*1){
                        layer.msg('您的出价太高且您输入的数量超过了产品发行数量！');
                    }
				}else{
					$.ajax({
						url: "",
						//请求的过程中传递过去的参数 json
						data: {
							goods_id:id,
							price:$('#offer').val(),
							num:$('#stock_num').val()
						},
						//成功了的回调，并且带有返回值
						success: function(data) {
							layer.msg(msg, {
								icon: 1,
								time: 1000 //2秒关闭（如果不配置，默认是3秒）
							}, function() {
								if(data.code==200){
									//location.href = url;									
								}
							});
						}
					})

				}
				
            })

            $(".close-stock").click(function(){
                $(".my-modal").css("display","none");
            })


        </script>
	    <script>
            var offer = document.getElementById('offer');
            function amount(th){
                var regStrs = [
                    ['^0(\\d+)$', '$1'], //禁止录入整数部分两位以上，但首位为0
                    ['[^\\d\\.]+$', ''], //禁止录入任何非数字和点
                    ['\\.(\\d?)\\.+', '.$1'], //禁止录入两个以上的点
                    ['^(\\d+\\.\\d{2}).+', '$1'] //禁止录入小数点后两位以上
                ];
                for(var i=0; i<regStrs.length; i++){
                    var reg = new RegExp(regStrs[i][0]);
                    th.value = th.value.replace(reg, regStrs[i][1]);
                }
            }
		</script>

	</body>
</html>